package com.ymk.cmd;

import com.ymk.base.cmd.ACmd;
import com.ymk.base.cmd.CmdSign;
import com.ymk.base.exception.MallException;
import com.ymk.bo.mch.MchBO;
import com.ymk.core.code.cmd.MchCmdCode;
import com.ymk.service.IMchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.Objects;

@Service
public class MchDelCmd extends ACmd {

    @Override
    public CmdSign executeSop(HttpServletRequest request, CmdSign sign) throws Exception {
        CmdSign respSign = new CmdSign(sign);
        MchBO reqData = super.getData(sign, MchBO.class);

        MchBO delMchBO = new MchBO();
        delMchBO.setId(reqData.getId());
        this.mchService.del(delMchBO);

        return respSign;
    }

    @Override
    public CmdSign verify(HttpServletRequest request, CmdSign sign) throws Exception {
        MchBO reqData = super.getData(sign, MchBO.class);
        if (Objects.isNull(reqData.getId())){
            throw new MallException("商户Id为空");
        }
        return null;
    }

    @Override
    public String getCmdCode() {
        return MchCmdCode.MCH_DEL;
    }

    @Autowired
    private IMchService mchService;
}